package com.springCloudStudy.controller;

import com.commons.interfaces.entities.Payment;
import com.commons.interfaces.utils.ResponseData;
import com.springCloudStudy.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;


/**
 * @PROJECT_NAME: SpringCloud_Study_atGuiGU
 * @NAME: Payment80001
 * @Author: lidongming
 * @DATE: 2022/2/6
 * @Desc:
 */
@RequestMapping("/payment")
@Slf4j
@RestController
public class PaymentController {

    @Value("${server.port}")
    private String ServerPort;
    @Autowired
    PaymentService paymentService;
    @PostMapping
    public ResponseData createPayment(@RequestBody Payment payment){
        log.info("插入数据");
        int result = paymentService.create(payment);
        return result>0?  new ResponseData(200,"插入数据库成功"+ServerPort,result): new ResponseData(444,"插入数据库失败",result);
    }
    @GetMapping("/{id}")
    public ResponseData queryById(@PathVariable Long id){
        log.info("查询数据"+id);
        Payment result = paymentService.getPaymentById(id);
        return result!=null? new ResponseData(200,"查询成功^_^"+ServerPort,result):new ResponseData(404,"查询失败-_-!",null);
    }
}
